package com.dubito.palette

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color
import android.os.Bundle
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.palette.graphics.Palette


class PaletteBaseActivity : AppCompatActivity() {

    private lateinit var bitmap: Bitmap

    private lateinit var tvDarkMutedColor: TextView
    private lateinit var tvDarkVibrantColor: TextView
    private lateinit var tvLightVibrantColor: TextView
    private lateinit var tvLightMutedColor: TextView
    private lateinit var tvVibrantColor: TextView
    private lateinit var tvMutedColor: TextView
    private lateinit var imageView: ImageView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_palette_base)

        initView()
        getPaletteColor()
    }

    private fun getPaletteColor() {
        Palette.from(bitmap).generate {
            val darkMutedColor = it!!.getDarkMutedColor(Color.BLUE)
            val darkVibrantColor = it.getDarkVibrantColor(Color.BLUE)
            val lightVibrantColor = it.getLightVibrantColor(Color.BLUE)
            val lightMutedColor = it.getLightMutedColor(Color.BLUE)
            val vibrantColor = it.getVibrantColor(Color.BLUE)
            val mutedColor = it.getMutedColor(Color.BLUE)

            tvDarkMutedColor.setBackgroundColor(darkMutedColor)
            tvDarkVibrantColor.setBackgroundColor(darkVibrantColor)
            tvLightMutedColor.setBackgroundColor(lightMutedColor)
            tvLightVibrantColor.setBackgroundColor(lightVibrantColor)
            tvMutedColor.setBackgroundColor(mutedColor)
            tvVibrantColor.setBackgroundColor(vibrantColor)
        }
    }

    private fun initView() {
        bitmap = BitmapFactory.decodeResource(resources, R.drawable.fj)
        tvDarkMutedColor = findViewById(R.id.tvDarkMutedColor)
        tvDarkVibrantColor = findViewById(R.id.tvDarkVibrantColor)
        tvLightVibrantColor = findViewById(R.id.tvLightVibrantColor)
        tvLightMutedColor = findViewById(R.id.tvLightMutedColor)
        tvVibrantColor = findViewById(R.id.tvVibrantColor)
        tvMutedColor = findViewById(R.id.tvMutedColor)
        imageView = findViewById(R.id.imageView)
        imageView.setImageBitmap(bitmap)
    }
}